const express = require('express');
const router = express.Router();
const { check } = require('express-validator');
const userController = require('../controllers/userController');
const authMiddleware = require('../middleware/auth');

router.post(
    '/register',
    [
      check('email').isEmail().withMessage('Invalid email'),
      check('full_name').notEmpty().withMessage('Full name is required'),
      check('username').notEmpty().withMessage('Username is required'),
      check('password').isLength({ min: 6 }).withMessage('Password must be at least 6 characters')
    ],
    userController.register
);

router.post(
    '/login',
    [
      check('email').isEmail().withMessage('Invalid email'),
      check('password').notEmpty().withMessage('Password is required')
    ],
    userController.login
);

router.get('/:user_id', userController.getProfile);

router.put(
    '/',
    authMiddleware,
    [
      check('email').optional().isEmail().withMessage('Invalid email'),
      check('username').optional().notEmpty().withMessage('Username is required')
    ],
    userController.updateProfile
);

module.exports = router;